package com.k.kppcloud.consumer;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 测试 内部调用 provider 服务及负载均衡
 *
 * 注意：feign 包扫描
 * 注意： 需要排除 ribbon 负载均衡器，添加 Spring Cloud Loadbalancer 负载均衡器
 * <dependency>
 *      <groupId>com.alibaba.cloud</groupId>
 *       <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
 *        <exclusions>
 *              <!-- 将ribbon排除 使用 spring-cloud-starter-loadbalancer -->
 *             <exclusion>
 *                  <groupId>org.springframework.cloud</groupId>
 *                  <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
 *             </exclusion>
 *        </exclusions>
 *  </dependency>
 *  <dependency>
 *       <groupId>org.springframework.cloud</groupId>
 *        <artifactId>spring-cloud-starter-loadbalancer</artifactId>
 *  </dependency>
 */
@EnableDiscoveryClient
@EnableFeignClients(value = {"com.k.kppcloud.consumer.feign","com.k.kppcloud.consumer.controller"})
@Controller
@SpringBootApplication
public class InnerConsumerApp {
    public static void main( String[] args ) {
        SpringApplication.run(InnerConsumerApp.class);
    }

    @Value("${spring.application.name}")
    private String serverName;
    @Value("${server.port}")
    private String serverPort;
    @RequestMapping("/")
    @ResponseBody
    public Map<String,String> index(){
        Map<String,String> map = new HashMap<>();
        map.put("service",serverName);
        map.put("port",serverPort);
        return map;
    }

}
